﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Assessment.Management.SharedComponent.Params.ManagerParam;
using Assessment.Management.SharedComponent.Constants;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Assessment.Management.UI.Admin.Upload
{
    public class Uploadfile
    {
        public void Upload(string path,string table)
        {
                string excelConectiString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0", path);
                OleDbConnection conection = new OleDbConnection();
                conection.ConnectionString = excelConectiString;
                OleDbCommand command = new OleDbCommand("Select * from [Sheet1$]", conection);

                conection.Open();
                OleDbDataReader dr = command.ExecuteReader();
                string sqlConnectionstring = @"Data Source=laptopleson-pc\sqlexpress;Initial Catalog=FormManagement;Integrated Security=True";
                SqlBulkCopy bulkInsert = new SqlBulkCopy(sqlConnectionstring);
                bulkInsert.DestinationTableName = table;
                bulkInsert.WriteToServer(dr);


        }
    }
}